#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;

const ll P=1e9+7;
struct mat{
	ll a[3][3];
}O;
mat operator*(const mat& x,const mat& y){
	mat z=O;
	for(int i=0;i<3;i++) for(int j=0;j<3;j++) for(int k=0;k<3;k++) (z.a[i][j]+=x.a[i][k]*y.a[k][j])%=P;
	return z;
}
mat qpow(mat x,int y){
	mat z=O;z.a[0][0]=z.a[1][1]=z.a[2][2]=1;
	while(y){if(y&1)z=z*x;x=x*x,y>>=1;}
	return z;
}

ll n,m,X;
int32_t main(){
	freopen("pearl.in","r",stdin);
	freopen("pearl.out","w",stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	ll i;char ch;
	cin>>n>>m>>X;
	if(X==1&&m==1){
		n--;
		mat z=O;z.a[0][0]=z.a[0][1]=z.a[1][0]=z.a[2][1]=1;z.a[1][1]=P-1;z.a[2][2]=2;
		mat a=O;a.a[0][2]=1;
		a=a*qpow(z,n-1);
		cout<<(a.a[0][0]+a.a[0][1])%P<<'\n';
		return 0;
	}
	return 0;
}